home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Cafe 3
/
Visual Cafe 3.ISO
/
Vcafe
/
Main.bin
/
JavaName.java
< prev
next >
Wrap
Text File
|
1998-09-08
|
4KB
|
228 lines
package com.symantec.itools.lang;
import java.io.File;
import java.io.Serializable;
import com.symantec.itools.io.FileSystem;
/**
* @author Symantec Internet Tools Division
* @version 1.0
* @since VCafe 3.0
*/
public class JavaName
implements Serializable
{
/**
* @since VCafe 3.0
*/
protected String packageName;
/**
* @since VCafe 3.0
*/
protected String name;
/**
* @since VCafe 3.0
*/
protected String extension;
public JavaName(String nm)
throws NotJavaNameException
{
this(nm, true);
}
public JavaName(String nm, boolean checkName)
throws NotJavaNameException
{
validateName(nm, checkName);
}
/**
* @since VCafe 3.0
*/
public String getPackage()
{
return (packageName);
}
/**
* @since VCafe 3.0
*/
public String getName()
{
return (name);
}
/**
* @param nm TODO
* @since VCafe 3.0
*/
public void setName(String nm)
{
name = nm;
}
/**
* @param pkg TODO
* @since VCafe 3.0
*/
public void setPackage(String pkg)
{
packageName = pkg;
}
/**
* @param ext TODO
* @since VCafe 3.0
*/
public void setExtension(String ext)
{
extension = ext;
}
/**
* @since VCafe 3.0
*/
public String getExtension()
{
return (extension);
}
/**
* @param nm TODO
* @param checkName TODO
* @exception com.symantec.itools.lang.NotJavaNameException
* @since VCafe 3.0
*/
protected void validateName(String nm, boolean checkName)
throws NotJavaNameException
{
int namePos;
int nameEndPos;
int extPos;
namePos = nm.lastIndexOf('/');
if(namePos == 0)
{
throw new NotJavaNameException(nm);
}
if(namePos == -1)
{
packageName = "/";
}
else if(namePos > 0)
{
packageName = getNamePart(nm, 0, namePos);
}
extPos = nm.lastIndexOf('.');
if(extPos < 0)
{
nameEndPos = nm.length();
}
else
{
nameEndPos = extPos;
}
if(checkName)
{
name = getNamePart(nm, namePos + 1, nameEndPos);
}
else
{
name = nm.substring(namePos + 1, nameEndPos);
}
if(extPos >= 0)
{
extension = nm.substring(extPos + 1);
}
}
/**
* @param nm TODO
* @param startPos TODO
* @param endPos TODO
* @since VCafe 3.0
*/
protected String getNamePart(String nm, int startPos, int endPos)
{
return (nm.substring(startPos, endPos).replace(File.separatorChar, '/'));
}
/**
* @since VCafe 3.0
*/
public String getFullName()
{
if(packageName.equals("/"))
{
if(extension == null)
{
return (name);
}
return (name + '.' + extension);
}
if(extension == null)
{
return (packageName + '/' + name);
}
return (packageName + '/' + name + '.' + extension);
}
/**
* @since VCafe 3.0
*/
public int hashCode()
{
return (getFullName().hashCode());
}
/**
* @param obj TODO
* @since VCafe 3.0
*/
public boolean equals(Object obj)
{
String fullName;
if(obj instanceof JavaName)
{
fullName = ((JavaName)obj).getFullName();
}
else if(obj instanceof String)
{
fullName = (String)obj;
}
else
{
return (false);
}
return (fullName.equals(getFullName()));
}
}